﻿using System.Configuration;
using System.Globalization;

namespace ManagedUIFlow.Infrastructure.Flows.Configuration
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface")]
    public class FlowsConfigurationElementCollection : ConfigurationElementCollection
    {        
        protected override bool ThrowOnDuplicate
        {
            get { return true; }
        }

        public void Add(FlowConfigurationElementCollection render)
        {
            BaseAdd(render);
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]
        public bool Contains(string renderName)
        {            
            return base.BaseGet(renderName.ToLower(CultureInfo.CurrentCulture)) != null;
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.BasicMap; }
        }

        protected override string ElementName
        {
            get { return "flow"; }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new FlowConfigurationElementCollection();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((FlowConfigurationElementCollection)element).Flow.ToLower(CultureInfo.CurrentCulture);
        }

        public FlowConfigurationElementCollection this[int index]
        {
            get { return (FlowConfigurationElementCollection)base.BaseGet(index); }
        }

        public new FlowConfigurationElementCollection this[string navigationGraphName]
        {
            get
            {
                return (FlowConfigurationElementCollection)base.BaseGet(navigationGraphName.ToLower(CultureInfo.CurrentCulture));
            }
        }
    }
}